package com.stx.common;

import com.stx.pojo.Match;
import com.stx.pojo.Player;

import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

public class Rank {
    public static List<Player> getRank(List<Player> list){
        int i = 1;
        List<Player> result = list.stream().sorted(new Comparator<Player>() {
            @Override
            public int compare(Player o1, Player o2) {
                if (o1.getAvgScore() == null || o2.getAvgScore() == null) {
                    return 0;
                }
                //根据分数由大到小排序
                return o2.getAvgScore().compareTo(o1.getAvgScore());
            }
        }).collect(Collectors.toList());
        for (Player player : result) {
            player.setRank(i++);
        }
        return result;
    }
}
